﻿//-------------------------------------------------------------
// 文件名称: product.js
// 描   述: 脚本语言
// 修改标识: Modify By 李传 2008-11-12
// 修改内容: 不显示配件商品 
//          function selectid(path)中fitobj[i].value.indexof("fitting")
//          改为fitobj[i].name.indexOf("fitting_9");
//-------------------------------------------------------------
function selecttabpro(obj, index, areaname){
    var node = childs(obj.parentNode.childNodes);
    for(var i=0;i<node.length;i++){
		node[i].id = "";
		getobj(areaname + (i+1)).style.display = "none";	
	}
	obj.id = "proselect";
	getobj(areaname + index).style.display = "";
}

function selectid(path){
    if($("#detailprice").html() == "--"){
        alert("该商品组合不存在");
		return false;
    }
	var storage = $("#storage")[0].value;
    var proid = document.getElementById("proid").value;
	var outofstock = $("#outofstock")[0].value;
	
	if(storage <= 0){
		if(outofstock == "0"){
			if(confirm('库存不足，是否进行缺货登记')){
				window.location.href=path + 'productreg.aspx?id=' + proid;
			}
		}else{
			alert('库存不足!');	
		}
		return false;	
	}
	//自定义属性
    var selfpropobj = document.getElementsByName("selfproperty");
	var selfproperty = "";
	for(var i=0;i<selfpropobj.length;i++){
        if(i==0){
            selfproperty = selfpropobj[i].options[selfpropobj[i].selectedIndex].value;
        }else{
            selfproperty += "," + selfpropobj[i].options[selfpropobj[i].selectedIndex].value;
        }
    }
	
	//商品属性
    var propobj = document.getElementsByName("property");
	var count = $("#buynum")[0].value;
	//.value;
	if (count == "0") 
		count = "1";
    var url = path + "cart.aspx?id=" + proid + "&act=buy&count=" + count + "&prop=";
    var propvalue = "";
    var propname = "";
    
    var fit = "";
    
    //获取选中商品ID  Mod By 钟登科 2008-11-24
    var fitobj = document.getElementsByTagName("input");
    for(var i = 0; i < fitobj.length; i++){
        if(fitobj[i].name.indexOf("fitting_") != -1)
        {
            if(fitobj[i].checked)
            {
                fit += "," + fitobj[i].value;
            }
        }
    }

    for(var i=0;i<propobj.length;i++){
        if(i==0){
            propvalue = propobj[i].value;
            propname = propobj[i].options[propobj[i].selectedIndex].propname + ":" +propobj[i].options[propobj[i].selectedIndex].text;
        }else{
            propvalue += "," + propobj[i].value;
            propname += "<br>" + propobj[i].options[propobj[i].selectedIndex].propname + ":" + propobj[i].options[propobj[i].selectedIndex].text;
        }
    }
	
	var price = "0";
	if($("#detailprice")){
		price = $("#detailprice")[0].innerHTML;
	}
	
	//url = url + propvalue + "&propname=" + escape(propname) + "&selfprop=" + escape(selfproperty) + "&fit=" + fit + "&price=" + price;
	
	/*var myajax = new Ajax.Updater(    
		{success: 'aaa'},     
		url,    
		{    
			asynchronous:true,    
			method: 'get',    
			evalscrīpts:true,
			onComplete : judgeexit  
		}    
	);
	
	var myajax1 = new Ajax.Updater(    
		{success: 'cartStatus'},     
		path + "js_initalert.aspx?id=" + proid,    
		{    
			asynchronous:true,    
			method: 'get',    
			evalscrīpts:true,
			onComplete : showCartInfo  
		}    
	);*/

    window.location.href = url + propvalue + "&propname=" + escape(propname) + "&selfprop=" + escape(selfproperty) + "&fit=" + fit + "&price=" + price;
	return false;
}

function closeStatus(){
	document.getElementById('Layer2').style.display='none';	
}

//AJAX获取价格
function GetPriceDetail(path, id){
	var pstr = ",";
	var propertys = document.getElementsByName("property");
	if(propertys){
		for(var i=0;i<propertys.length;i++){
			pstr += propertys[i].value + ",";
		}
	}
//	alert(pstr);
	//if(pstr != ","){
	var url = path + "product.aspx?id="+ id +"&act=detailprice&pstr=" + pstr + "&d=" + Date();

	/* var myajax = new Ajax.Updater(    
		{success: 'detailprice'},     
		url,    
		{    
			asynchronous:true,    
			method: 'get',    
			evalscrīpts:true,
			onComplete : judgeexit  
		}    
	);   */
	var data = "";
	$.get(url, {Action:"get"}, function (data) {judgeexit(data);});
	//}
}

function judgeexit(data){
	$("#detailprice")[0].innerHTML = data;
	
    if($("#detailprice")[0].innerHTML == "--"){
        alert("该商品组合不存在");
    }
	else{
		var obj = $("select[name='property']");
		
		obj.each(function(){
			if($(this)[0].style.display != 'none')
			{
				$("#detailprice")[0].innerHTML = ($("#detailprice")[0].innerHTML * dis / 100).toFixed(2);
				return;
			}
		}); 		
    }
}
